#!/usr/bin/env python
# encoding:utf-8
# Author: jixingxing

from sqlalchemy import create_engine

# 1、首先创建引擎,使用什么样的方式操作mysql
# engine = create_engine("mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]")
engine = create_engine("mysql+pymysql://testuser:testuserpasswd@112.74.209.145:3306/test1", max_overflow=5)

# 2、接下来就可以执行SQL语句了 ,创建游标

# cur = engine.execute("show tables")
# cur = engine.execute("create table tb1 (id int(4),name char(40)) ENGINE=MyISAM DEFAULT CHARSET=utf8")
# cur = engine.execute("insert into tb1 (id,name) values(1,'zhoujie')")
# cur = engine.execute("insert into tb1 (id,name) values(%s,%s)",
#                      [(2,'jiyanning'),(3,'jixingxing')])
# cur = engine.execute(
#     "INSERT INTO hosts (host, color_id) VALUES (%(host)s, %(color_id)s)",
#     host='1.1.1.99', color_id=3
# )


cur = engine.execute("select * from tb1")

# 3、新插入自增ID
# cur.lastrowid

# 4、获取数据
data = cur.fetchall()

print(data)

